package com.punai.standard.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punai.common.core.domain.TreeBo;
import com.punai.standard.domain.StaClChapter;
import com.punai.standard.mapper.StaClChapterMapper;
import com.punai.standard.service.IStaClChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 材料章节Service业务层处理
 *
 * @author zhx
 * @date 2022-12-21
 */
@Service
public class StaClChapterServiceImpl extends ServiceImpl<StaClChapterMapper,StaClChapter> implements IStaClChapterService
{
    @Autowired
    private StaClChapterMapper staClChapterMapper;

    @Override
    public List<TreeBo> treeData(String versionsId) {
        List<TreeBo> result = new ArrayList<>();
        LambdaQueryWrapper<StaClChapter> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(StaClChapter::getVersionId,versionsId);
        List<StaClChapter> chapters = staClChapterMapper.selectList(queryWrapper);
        if (CollUtil.isEmpty(chapters)) {
            return result;
        }
        result = TreeBo.convert(chapters);
        return result;
    }

}
